<!--
 * @Description: 打开app
-->
<template>
	<div class="open_app">
		<wx-open-launch-app id="launch-btn" :extinfo="extinfo" appid="wxdb8b21091717ff69">
			<script type="text/wxtag-template">
				<div style="width:100%;height:1000px;">
        </div>
      </script>
		</wx-open-launch-app>
	</div>
</template>

<script>
	import wx from 'weixin-js-sdk';
	const app = getApp();
	import Vue from 'vue'
	import {
		getConfigParam1
	} from '@/api/home.js';
	export default {
		props: {
			shareUrl: {
				type: String,
				required: true,
				default: ''
			},
		},
		components: {

		},
		data() {
			return {
				extinfo: 'usercase',
				wxAppId: 'wxdb8b21091717ff69'
			}
		},
		mounted: function() {
			let that = this;
			that.initWxSDK();

			var btn = document.getElementById('launch-btn');
			btn.addEventListener('launch', function(e) {
				console.log(e);
				// setTimeout(() => {
				// 	window.location.href =
				// 		'https://www.mae.vip/MaYiAPP1.2/login/todownloadapp/0/54862658/introduce';
				// }, 3000)
			});
			btn.addEventListener('error', function(e) {
				console.log('fail', e.detail);
				// uni.showToast({
				// 	title: e.detail,
				// 	icon: 'none'
				// })
				setTimeout(() => {
					window.location.href =
						'https://www.mae.vip/MaYiAPP1.2/login/todownloadapp/0/54862658/introduce';
				}, 1000)
			});
		},
		methods: {
			initWxSDK() {
				let that = this;
				let p = {};
				//let str = 'https://www.mayimae.com/qz/pages/workshop/share';
				p.url = encodeURI(that.shareUrl);
				getConfigParam1(p).then(res => {
					wx.config({
						debug: false,
						appId: 'wx92b0e22e2be1ea76',
						timestamp: res.timestamp,
						nonceStr: res.nonceStr,
						signature: res.signature,
						jsApiList: ['onNeedPrivacyAuthorization'],
						openTagList: ['wx-open-launch-app'] // 关键！
					});
					wx.ready((res) => {
						//console.log('成功--------' + JSON.stringify(res));
					});
					wx.error(res => {
						//console.log('失败---------' + JSON.stringify(res));
					});
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.open_app {
		position: absolute;
		top: 0;
		left: 0;
		z-index: 1;
		width: 100%;
		height: 100%;
		overflow: hidden;

		#launch-btn {
			display: block;
		}
	}
</style>